/*
 * @Author: tangyuhui 317972442@qq.com
 * @Date: 2024-08-29 18:12:09
 * @LastEditors: tangyuhui 317972442@qq.com
 * @LastEditTime: 2024-09-30 09:07:01
 */
// 适用于 React 17 或更早版本
import React from "react";
import ReactDOM from "react-dom";
import Sidebar from "./views/Dashboard/Sidebar";
import {getYunXiaoElements} from './views/Dashboard/yunxiao'

const app = document.createElement("div");
app.id = "chrome-extension-sidebar-root";
document.body.appendChild(app);

ReactDOM.render(<Sidebar />, app);

chrome.runtime.onMessage.addListener((request, sender, sendResponse) => {
  if (request.action === "getElements" || request.action === "getData") {
    const results = getYunXiaoElements()

    // 发送数据到 background script
    chrome.runtime.sendMessage({ action: "saveData", data: results }, function(response) {
      console.log("Data has been sent to background script.");
    });
    // 发送获取到的元素内容作为响应
    sendResponse({ data: results });
  }
});
